<template>
    <view>
        <van-collapse ref="collapse" v-model="activeNames">
            <van-space direction="vertical" fill size="1rem">
                <van-cell-group inset>
                    <van-cell
                        icon="location-o"
                        :title="orgData['orgNameChin']"
                        @click="clickChild(orgData['orgId'], orgData['orgCode'])"
                    />
                </van-cell-group>

                <!--    <van-cell-group v-for="org in orgDataList" :key = "org.orgId"  inset>
        <van-collapse-item :title="org.orgNameChin"  name ="1" >
            <van-cell icon="location-o"  v-for="item in org.childOrgList" :key="item.orgId" :title="item.orgNameChin" @click = "toAlert(item.orgId)" />
        </van-collapse-item>
    </van-cell-group>-->

                <van-cell-group v-for="orgTwo in orgDataListTwo" :key="orgTwo.orgId" inset>
                    <van-collapse-item
                        :title="orgTwo.orgNameChin"
                        :name="orgTwo.code"
                        @click.stop.prevent="clickChild(orgTwo.orgId, orgTwo.orgCode)"
                    >
                        <van-cell
                            icon="location-o"
                            v-for="item in orgTwo.childOrgList"
                            :key="item.orgId"
                            :title="item.orgNameChin"
                            @click.stop.prevent="clickChild(item.orgId, item.orgCode)"
                        />
                    </van-collapse-item>
                </van-cell-group>
            </van-space>
        </van-collapse>
    </view>
</template>

<script setup>
import { events } from '../../utils/bus';
import { onMounted, ref, defineEmits } from 'vue';
import { getOrgList } from '@/api/org/index';

const orgData = ref([]);
const orgDataList = ref([]);
const orgDataListTwo = ref([]);
onMounted(async function () {
    const { resultData } = await getOrgList({ chartId: 'APP_01010101' });
    //澳门一级
    orgData.value = resultData.currentOrg;
    console.log(orgData);
    //选择监督实体一级
    orgDataList.value = resultData['orgList'];
    //选择局级一级
    orgDataListTwo.value = resultData['orgList'][0]['childOrgList'];
});

const activeNames = ref(['0']);
const collapse = ref(null);

function toAlert(id) {
    alert(id);
    eventEmit();
}

const eventEmit = () => {
    events.emit('orgSelect', '123');
};
const emit = defineEmits(['clickChild']);
function clickChild(id, code) {
    let param = {
        orgId: id,
        orgCode: code
    };
    //传递给父组件
    emit('clickChildOrg', param);
}
</script>

<style scoped></style>
